import 'package:film/service/api_service.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// 留言页面控制器
class MessageController extends GetxController {
  final DioService apiService = DioService();
  late TextEditingController messageController;

  /// 留言内容
  var message = ''.obs;

  /// 最大字数
  final int maxLength = 200;

  @override
  void onInit() {
    super.onInit();
    messageController = TextEditingController();
  }

  @override
  void onClose() {
    messageController.dispose();
    super.onClose();
  }

  /// 提交留言
  void submitMessage() async {
    if (message.value.trim().isEmpty) {
      Get.snackbar('提示', '请输入留言内容');
      return;
    }
    final ApiResponse<void> response = await apiService.addLeaveMessage(content: message.value.trim());
    if (response.success) {
      Get.snackbar('成功', '留言已提交');
    }
    // 清空输入
    messageController.clear();
    message.value = '';
  }
}
